<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no"/>
<xsl:template match="/dataroot"><![CDATA[BEGIN{FS="\x01"]]>
<xsl:apply-templates select="Fields"/>}<![CDATA[NF>1 {
  for(i=1; i<=NF;i++){
    pos=index($i,"=")
    if(pos==0){
      printf("%s%s",$i, i<NF?FS:"")
      continue
    }
    key=substr($i,1,pos-1)
    val=substr($i,pos)
    tag=strtonum(key)
    printf("%s%s%s",length(tag)==length(key) && tag in tags ? tags[tag]:key, val,i<NF ? "|" :"")
  }
  print ""
}
NF<=1{print $0}]]>
</xsl:template>

<xsl:template match="Fields">tags[<xsl:value-of select="Tag"/>]="<xsl:value-of select="FieldName"/>"
</xsl:template>
</xsl:stylesheet>
